package com.fac.controller.admin;

import com.fac.dto.InspectionPlanCreateDTO;
import com.fac.dto.InspectionPlanPageQueryDTO;
import com.fac.dto.InspectionRecordCreateDTO;
import com.fac.result.PageResult;
import com.fac.result.Result;
import com.fac.service.InspectionPlanService;
import com.fac.service.InspectionRecordService;
import com.fac.vo.InspectionPlanCreateVO;
import com.fac.vo.InspectionPlanVO;
import com.fac.vo.InspectionRecordCreateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * 巡检管理Controller
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "管理端-巡检管理接口")
@Slf4j
public class InspectionController {

    @Autowired
    private InspectionPlanService inspectionPlanService;

    @Autowired
    private InspectionRecordService inspectionRecordService;

    /**
     * 创建巡检计划
     */
    @PostMapping("/inspectionPlans")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiOperation("创建巡检计划")
    public Result<InspectionPlanCreateVO> createPlan(@RequestBody InspectionPlanCreateDTO createDTO) {
        log.info("创建巡检计划：{}", createDTO);
        InspectionPlanCreateVO vo = inspectionPlanService.create(createDTO);
        return Result.success(vo);
    }

    /**
     * 巡检计划列表
     */
    @GetMapping("/inspectionPlans")
    @ApiOperation("巡检计划列表")
    public Result<PageResult> planList(InspectionPlanPageQueryDTO queryDTO) {
        log.info("查询巡检计划列表：{}", queryDTO);
        PageResult pageResult = inspectionPlanService.pageQuery(queryDTO);
        return Result.success(pageResult);
    }

    /**
     * 提交巡检记录
     */
    @PostMapping("/inspectionRecords")
    @ResponseStatus(HttpStatus.CREATED)
    @ApiOperation("提交巡检记录")
    public Result<InspectionRecordCreateVO> createRecord(@RequestBody InspectionRecordCreateDTO createDTO) {
        log.info("提交巡检记录：{}", createDTO);
        InspectionRecordCreateVO vo = inspectionRecordService.create(createDTO);
        return Result.success(vo);
    }
} 